package fag.core.game.test.asteroids;

import fag.core.game.StandardDoodad;
import fag.core.geometry.Vector2D;
import fag.core.model.Model;

public class Meteorite extends StandardDoodad {

	private Vector2D speed;
	private int life;
	
	public Meteorite(Model model, Vector2D position, Vector2D speed, double angle, int life) {
		super(model);
		setTranslation(position);
		this.speed = speed;
		addRotation(angle);
		this.life = life;
	}
	
	public int getLife() {
		return life;
	}
	
	public void lostOneLife() {
		if(life > 0) {
			life--;
		}
	}
	
	public void addRotation(double angle) {
		rotate(angle, getBounds().getWidth() / 2.0, getBounds().getHeight() / 2.0, Referential.RELATIVE);
	}
	
	public void bounce(Vector2D normal) {
		speed.set(speed.add(normal.mul(normal.dot(speed.mul(-1)) * 2)));
	}

	public void step(double dt) {
		translate(speed.x * dt, speed.y * dt, Referential.ABSOLUTE);
	}
}
